<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>事件代理</title>
</head>
<body>
    <a href="#">链接1号</a>
    <a href="#">链接2号</a>
    <a href="#">链接3号</a>
    <a href="#">链接4号</a>
    <a href="#">链接5号</a>
    <a href="#">链接6号</a>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js" type="text/javascript"></script>
<script>
  const aNodes = document.getElementsByTagName('a')
  console.log('aNodes are', aNodes);
  $.each(aNodes, function (index, aNode) {
    console.log(`DOM类数组的第${index}个元素是${aNode.innerText}`)
  })

  const arr = [1, 2, 3]
  // 通过调用iterator，拿到迭代器对象
  const iterator = arr[Symbol.iterator]()
  console.log(iterator);

  // 对迭代器对象执行next，就能逐个访问集合的成员
  // console.log(iterator.next())
  // console.log(iterator.next())
  // console.log(iterator.next())
  // console.log(iterator.next())
  // 初始化一个迭代结果
  let now = { done: false }

  // 循环往外迭代成员
  while(!now.done) {
      now = iterator.next()
      if(!now.done) {
          console.log(`现在遍历到了${now.value}`)
      }
  }

  // 实现自己的迭代器
  function myIteratorGenerator(list) {
    let index = 0;
    let len = list.length;
    return {
      next: function() {
        let finish = index >= len;
        let value = null;
        value = !finish ? list[index++]: null;
        return {
          done: finish,
          value
        }
      }
    }
  }

  let myIterator = myIteratorGenerator(['1号选手','2号选手','3号选手']);
  console.log(myIterator.next());
  console.log(myIterator.next());
  console.log(myIterator.next());
  

</script>
</html>